home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / tools / gcc / gcc270_src.lha / gcc-2.7.0-amiga / config / alpha / alpha.c next >
Encoding:
C/C++ Source or Header  |  1995-06-16  |  46.8 KB  |  1,693 lines

  1. /* Subroutines used for code generation on the DEC Alpha.
  2.    Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  3.    Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.  */
  21.  
  22.  
  23. #include <stdio.h>
  24. #include "config.h"
  25. #include "rtl.h"
  26. #include "regs.h"
  27. #include "hard-reg-set.h"
  28. #include "real.h"
  29. #include "insn-config.h"
  30. #include "conditions.h"
  31. #include "insn-flags.h"
  32. #include "output.h"
  33. #include "insn-attr.h"
  34. #include "flags.h"
  35. #include "recog.h"
  36. #include "reload.h"
  37. #include "expr.h"
  38. #include "obstack.h"
  39. #include "tree.h"
  40.  
  41. /* Save information from a "cmpxx" operation until the branch or scc is
  42.    emitted.  */
  43.  
  44. rtx alpha_compare_op0, alpha_compare_op1;
  45. int alpha_compare_fp_p;
  46.  
  47. /* Save the name of the current function as used by the assembler.  This
  48.    is used by the epilogue.  */
  49.  
  50. char *alpha_function_name;
  51.  
  52. /* Non-zero if inside of a function, because the Alpha asm can't
  53.    handle .files inside of functions.  */
  54.  
  55. static int inside_function = FALSE;
  56.  
  57. /* Nonzero if the current function needs gp.  */
  58.  
  59. int alpha_function_needs_gp;
  60.  
  61. extern char *version_string;
  62. extern int rtx_equal_function_value_matters;
  63.  
  64. /* Declarations of static functions.  */
  65. static void alpha_set_memflags_1  PROTO((rtx, int, int, int));
  66. static void add_long_const    PROTO((FILE *, HOST_WIDE_INT, int, int, int));
  67.  
  68. /* Returns 1 if VALUE is a mask that contains full bytes of zero or ones.  */
  69.  
  70. int
  71. zap_mask (value)
  72.      HOST_WIDE_INT value;
  73. {
  74.   int i;
  75.  
  76.   for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
  77.        i++, value >>= 8)
  78.     if ((value & 0xff) != 0 && (value & 0xff) != 0xff)
  79.       return 0;
  80.  
  81.   return 1;
  82. }
  83.  
  84. /* Returns 1 if OP is either the constant zero or a register.  If a
  85.    register, it must be in the proper mode unless MODE is VOIDmode.  */
  86.  
  87. int
  88. reg_or_0_operand (op, mode)
  89.       register rtx op;
  90.       enum machine_mode mode;
  91. {
  92.   return op == const0_rtx || register_operand (op, mode);
  93. }
  94.  
  95. /* Return 1 if OP is a constant in the range of 0-63 (for a shift) or
  96.    any register.  */
  97.  
  98. int
  99. reg_or_6bit_operand (op, mode)
  100.      register rtx op;
  101.      enum machine_mode mode;
  102. {
  103.   return ((GET_CODE (op) == CONST_INT
  104.        && (unsigned HOST_WIDE_INT) INTVAL (op) < 64)
  105.       || register_operand (op, mode));
  106. }
  107.  
  108.  
  109. /* Return 1 if OP is an 8-bit constant or any register.  */
  110.  
  111. int
  112. reg_or_8bit_operand (op, mode)
  113.      register rtx op;
  114.      enum machine_mode mode;
  115. {
  116.   return ((GET_CODE (op) == CONST_INT
  117.        && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100)
  118.       || register_operand (op, mode));
  119. }
  120.  
  121. /* Return 1 if OP is an 8-bit constant.  */
  122.  
  123. int
  124. cint8_operand (op, mode)
  125.      register rtx op;
  126.      enum machine_mode mode;
  127. {
  128.   return (GET_CODE (op) == CONST_INT
  129.       && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100);
  130. }
  131.  
  132. /* Return 1 if the operand is a valid second operand to an add insn.  */
  133.  
  134. int
  135. add_operand (op, mode)
  136.      register rtx op;
  137.      enum machine_mode mode;
  138. {
  139.   if (GET_CODE (op) == CONST_INT)
  140.     return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')
  141.         || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')
  142.         || CONST_OK_FOR_LETTER_P (INTVAL (op), 'O'));
  143.  
  144.   return register_operand (op, mode);
  145. }
  146.  
  147. /* Return 1 if the operand is a valid second operand to a sign-extending
  148.    add insn.  */
  149.  
  150. int
  151. sext_add_operand (op, mode)
  152.      register rtx op;
  153.      enum machine_mode mode;
  154. {
  155.   if (GET_CODE (op) == CONST_INT)
  156.     return ((unsigned HOST_WIDE_INT) INTVAL (op) < 255
  157.         || (unsigned HOST_WIDE_INT) (- INTVAL (op)) < 255);
  158.  
  159.   return register_operand (op, mode);
  160. }
  161.  
  162. /* Return 1 if OP is the constant 4 or 8.  */
  163.  
  164. int
  165. const48_operand (op, mode)
  166.      register rtx op;
  167.      enum machine_mode mode;
  168. {
  169.   return (GET_CODE (op) == CONST_INT
  170.       && (INTVAL (op) == 4 || INTVAL (op) == 8));
  171. }
  172.  
  173. /* Return 1 if OP is a valid first operand to an AND insn.  */
  174.  
  175. int
  176. and_operand (op, mode)
  177.      register rtx op;
  178.      enum machine_mode mode;
  179. {
  180.   if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
  181.     return (zap_mask (CONST_DOUBLE_LOW (op))
  182.         && zap_mask (CONST_DOUBLE_HIGH (op)));
  183.  
  184.   if (GET_CODE (op) == CONST_INT)
  185.     return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
  186.         || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100
  187.         || zap_mask (INTVAL (op)));
  188.  
  189.   return register_operand (op, mode);
  190. }
  191.  
  192. /* Return 1 if OP is a valid first operand to an IOR or XOR insn.  */
  193.  
  194. int
  195. or_operand (op, mode)
  196.      register rtx op;
  197.      enum machine_mode mode;
  198. {
  199.   if (GET_CODE (op) == CONST_INT)
  200.     return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
  201.         || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100);
  202.  
  203.   return register_operand (op, mode);
  204. }
  205.  
  206. /* Return 1 if OP is a constant that is the width, in bits, of an integral
  207.    mode smaller than DImode.  */
  208.  
  209. int
  210. mode_width_operand (op, mode)
  211.      register rtx op;
  212.      enum machine_mode mode;
  213. {
  214.   return (GET_CODE (op) == CONST_INT
  215.       && (INTVAL (op) == 8 || INTVAL (op) == 16 || INTVAL (op) == 32));
  216. }
  217.  
  218. /* Return 1 if OP is a constant that is the width of an integral machine mode
  219.    smaller than an integer.  */
  220.  
  221. int
  222. mode_mask_operand (op, mode)
  223.      register rtx op;
  224.      enum machine_mode mode;
  225. {
  226. #if HOST_BITS_PER_WIDE_INT == 32
  227.   if (GET_CODE (op) == CONST_DOUBLE)
  228.     return CONST_DOUBLE_HIGH (op) == 0 && CONST_DOUBLE_LOW (op) == -1;
  229. #endif
  230.  
  231.   return (GET_CODE (op) == CONST_INT
  232.       && (INTVAL (op) == 0xff
  233.           || INTVAL (op) == 0xffff
  234. #if HOST_BITS_PER_WIDE_INT == 64
  235.           || INTVAL (op) == 0xffffffff
  236. #endif
  237.           ));
  238. }
  239.  
  240. /* Return 1 if OP is a multiple of 8 less than 64.  */
  241.  
  242. int
  243. mul8_operand (op, mode)
  244.      register rtx op;
  245.      enum machine_mode mode;
  246. {
  247.   return (GET_CODE (op) == CONST_INT
  248.       && (unsigned HOST_WIDE_INT) INTVAL (op) < 64
  249.       && (INTVAL (op) & 7) == 0);
  250. }
  251.  
  252. /* Return 1 if OP is the constant zero in floating-point.  */
  253.  
  254. int
  255. fp0_operand (op, mode)
  256.      register rtx op;
  257.      enum machine_mode mode;
  258. {
  259.   return (GET_MODE (op) == mode
  260.       && GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode));
  261. }
  262.  
  263. /* Return 1 if OP is the floating-point constant zero or a register.  */
  264.  
  265. int
  266. reg_or_fp0_operand (op, mode)
  267.      register rtx op;
  268.      enum machine_mode mode;
  269. {
  270.   return fp0_operand (op, mode) || register_operand (op, mode);
  271. }
  272.  
  273. /* Return 1 if OP is a register or a constant integer.  */
  274.  
  275.  
  276. int
  277. reg_or_cint_operand (op, mode)
  278.     register rtx op;
  279.     enum machine_mode mode;
  280. {
  281.      return GET_CODE (op) == CONST_INT || register_operand (op, mode);
  282. }
  283.  
  284. /* Return 1 if OP is something that can be reloaded into a register;
  285.    if it is a MEM, it need not be valid.  */
  286.  
  287. int
  288. some_operand (op, mode)
  289.      register rtx op;
  290.      enum machine_mode mode;
  291. {
  292.   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
  293.     return 0;
  294.  
  295.   switch (GET_CODE (op))
  296.     {
  297.     case REG:  case MEM:  case CONST_DOUBLE:
  298.     case CONST_INT:  case LABEL_REF:  case SYMBOL_REF:  case CONST:
  299.       return 1;
  300.  
  301.     case SUBREG:
  302.       return some_operand (SUBREG_REG (op), VOIDmode);
  303.     }
  304.  
  305.   return 0;
  306. }
  307.  
  308. /* Return 1 if OP is a valid operand for the source of a move insn.  */
  309.  
  310. int
  311. input_operand (op, mode)
  312.      register rtx op;
  313.      enum machine_mode mode;
  314. {
  315.   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
  316.     return 0;
  317.  
  318.   if (GET_MODE_CLASS (mode) == MODE_FLOAT && GET_MODE (op) != mode)
  319.     return 0;
  320.  
  321.   switch (GET_CODE (op))
  322.     {
  323.     case LABEL_REF:
  324.     case SYMBOL_REF:
  325.     case CONST:
  326.         /* This handles both the Windows/NT and OSF cases.  */
  327.       return mode == ptr_mode || mode == DImode;
  328.  
  329.     case REG:
  330.       return 1;
  331.  
  332.     case SUBREG:
  333.       if (register_operand (op, mode))
  334.     return 1;
  335.       /* ... fall through ... */
  336.     case MEM:
  337.       return mode != HImode && mode != QImode && general_operand (op, mode);
  338.  
  339.     case CONST_DOUBLE:
  340.       return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
  341.  
  342.     case CONST_INT:
  343.       return mode == QImode || mode == HImode || add_operand (op, mode);
  344.     }
  345.  
  346.   return 0;
  347. }
  348.  
  349. /* Return 1 if OP is a SYMBOL_REF for a function known to be in this
  350.    file.  */
  351.  
  352. int
  353. current_file_function_operand (op, mode)
  354.      rtx op;
  355.      enum machine_mode mode;
  356. {
  357.   return (GET_CODE (op) == SYMBOL_REF
  358.       && ! profile_flag && ! profile_block_flag
  359.       && (SYMBOL_REF_FLAG (op)
  360.           || op == XEXP (DECL_RTL (current_function_decl), 0)));
  361. }
  362.  
  363. /* Return 1 if OP is a valid operand for the MEM of a CALL insn.  */
  364.  
  365. int
  366. call_operand (op, mode)
  367.      rtx op;
  368.      enum machine_mode mode;
  369. {
  370.   if (mode != Pmode)
  371.     return 0;
  372.  
  373.   return (GET_CODE (op) == SYMBOL_REF
  374.       || (GET_CODE (op) == REG
  375.           && (REGNO (op) == 27 || WINDOWS_NT)));
  376. }
  377.  
  378. /* Return 1 if OP is a valid Alpha comparison operator.  Here we know which
  379.    comparisons are valid in which insn.  */
  380.  
  381. int
  382. alpha_comparison_operator (op, mode)
  383.      register rtx op;
  384.      enum machine_mode mode;
  385. {
  386.   enum rtx_code code = GET_CODE (op);
  387.  
  388.   if (mode != GET_MODE (op) || GET_RTX_CLASS (code) != '<')
  389.     return 0;
  390.  
  391.   return (code == EQ || code == LE || code == LT
  392.       || (mode == DImode && (code == LEU || code == LTU)));
  393. }
  394.  
  395. /* Return 1 if OP is a signed comparison operation.  */
  396.  
  397. int
  398. signed_comparison_operator (op, mode)
  399.      register rtx op;
  400.      enum machine_mode mode;
  401. {
  402.   switch (GET_CODE (op))
  403.     {
  404.     case EQ:  case NE:  case LE:  case LT:  case GE:   case GT:
  405.       return 1;
  406.     }
  407.  
  408.   return 0;
  409. }
  410.  
  411. /* Return 1 if this is a divide or modulus operator.  */
  412.  
  413. int
  414. divmod_operator (op, mode)
  415.      register rtx op;
  416.      enum machine_mode mode;
  417. {
  418.   switch (GET_CODE (op))
  419.     {
  420.     case DIV:  case MOD:  case UDIV:  case UMOD:
  421.       return 1;
  422.     }
  423.  
  424.   return 0;
  425. }
  426.  
  427. /* Return 1 if this memory address is a known aligned register plus
  428.    a constant.  It must be a valid address.  This means that we can do
  429.    this as an aligned reference plus some offset.
  430.  
  431.    Take into account what reload will do.
  432.  
  433.    We could say that out-of-range stack slots are alignable, but that would
  434.    complicate get_aligned_mem and it isn't worth the trouble since few
  435.    functions have large stack space.  */
  436.  
  437. int
  438. aligned_memory_operand (op, mode)
  439.      register rtx op;
  440.      enum machine_mode mode;
  441. {
  442.   if (GET_CODE (op) == SUBREG)
  443.     {
  444.       if (GET_MODE (op) != mode)
  445.     return 0;
  446.       op = SUBREG_REG (op);
  447.       mode = GET_MODE (op);
  448.     }
  449.  
  450.   if (reload_in_progress && GET_CODE (op) == REG
  451.       && REGNO (op) >= FIRST_PSEUDO_REGISTER)
  452.     op = reg_equiv_mem[REGNO (op)];
  453.  
  454.   if (GET_CODE (op) != MEM || GET_MODE (op) != mode
  455.       || ! memory_address_p (mode, XEXP (op, 0)))
  456.     return 0;
  457.  
  458.   op = XEXP (op, 0);
  459.  
  460.   if (GET_CODE (op) == PLUS)
  461.     op = XEXP (op, 0);
  462.  
  463.   return (GET_CODE (op) == REG
  464.       && (REGNO (op) == STACK_POINTER_REGNUM
  465.           || op == hard_frame_pointer_rtx
  466.           || (REGNO (op) >= FIRST_VIRTUAL_REGISTER
  467.           && REGNO (op) <= LAST_VIRTUAL_REGISTER)));
  468. }
  469.  
  470. /* Similar, but return 1 if OP is a MEM which is not alignable.  */
  471.  
  472. int
  473. unaligned_memory_operand (op, mode)
  474.      register rtx op;
  475.      enum machine_mode mode;
  476. {
  477.   if (GET_CODE (op) == SUBREG)
  478.     {
  479.       if (GET_MODE (op) != mode)
  480.     return 0;
  481.       op = SUBREG_REG (op);
  482.       mode = GET_MODE (op);
  483.     }
  484.  
  485.   if (reload_in_progress && GET_CODE (op) == REG
  486.       && REGNO (op) >= FIRST_PSEUDO_REGISTER)
  487.     op = reg_equiv_mem[REGNO (op)];
  488.  
  489.   if (GET_CODE (op) != MEM || GET_MODE (op) != mode)
  490.     return 0;
  491.  
  492.   op = XEXP (op, 0);
  493.  
  494.   if (! memory_address_p (mode, op))
  495.     return 1;
  496.  
  497.   if (GET_CODE (op) == PLUS)
  498.     op = XEXP (op, 0);
  499.  
  500.   return (GET_CODE (op) != REG
  501.       || (REGNO (op) != STACK_POINTER_REGNUM
  502.           && op != hard_frame_pointer_rtx
  503.           && (REGNO (op) < FIRST_VIRTUAL_REGISTER
  504.           || REGNO (op) > LAST_VIRTUAL_REGISTER)));
  505. }
  506.  
  507. /* Return 1 if OP is any memory location.  During reload a pseudo matches.  */
  508.  
  509. int
  510. any_memory_operand (op, mode)
  511.      register rtx op;
  512.      enum machine_mode mode;
  513. {
  514.   return (GET_CODE (op) == MEM
  515.       || (GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == REG)
  516.       || (reload_in_progress && GET_CODE (op) == REG
  517.           && REGNO (op) >= FIRST_PSEUDO_REGISTER)
  518.       || (reload_in_progress && GET_CODE (op) == SUBREG
  519.           && GET_CODE (SUBREG_REG (op)) == REG
  520.           && REGNO (SUBREG_REG (op)) >= FIRST_PSEUDO_REGISTER));
  521. }
  522.  
  523. /* REF is an alignable memory location.  Place an aligned SImode
  524.    reference into *PALIGNED_MEM and the number of bits to shift into
  525.    *PBITNUM.  */
  526.  
  527. void
  528. get_aligned_mem (ref, paligned_mem, pbitnum)
  529.      rtx ref;
  530.      rtx *paligned_mem, *pbitnum;
  531. {
  532.   rtx base;
  533.   HOST_WIDE_INT offset = 0;
  534.  
  535.   if (GET_CODE (ref) == SUBREG)
  536.     {
  537.       offset = SUBREG_WORD (ref) * UNITS_PER_WORD;
  538.       if (BYTES_BIG_ENDIAN)
  539.     offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref)))
  540.            - MIN (UNITS_PER_WORD,
  541.               GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref)))));
  542.       ref = SUBREG_REG (ref);
  543.     }
  544.  
  545.   if (GET_CODE (ref) == REG)
  546.     ref = reg_equiv_mem[REGNO (ref)];
  547.  
  548.   if (reload_in_progress)
  549.     base = find_replacement (&XEXP (ref, 0));
  550.   else
  551.     base = XEXP (ref, 0);
  552.  
  553.   if (GET_CODE (base) == PLUS)
  554.     offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
  555.  
  556.   *paligned_mem = gen_rtx (MEM, SImode,
  557.                plus_constant (base, offset & ~3));
  558.   MEM_IN_STRUCT_P (*paligned_mem) = MEM_IN_STRUCT_P (ref);
  559.   MEM_VOLATILE_P (*paligned_mem) = MEM_VOLATILE_P (ref);
  560.   RTX_UNCHANGING_P (*paligned_mem) = RTX_UNCHANGING_P (ref);
  561.  
  562.   *pbitnum = GEN_INT ((offset & 3) * 8);
  563. }
  564.  
  565. /* Similar, but just get the address.  Handle the two reload cases.  */
  566.  
  567. rtx
  568. get_unaligned_address (ref)
  569.      rtx ref;
  570. {
  571.   rtx base;
  572.   HOST_WIDE_INT offset = 0;
  573.  
  574.   if (GET_CODE (ref) == SUBREG)
  575.     {
  576.       offset = SUBREG_WORD (ref) * UNITS_PER_WORD;
  577.       if (BYTES_BIG_ENDIAN)
  578.     offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref)))
  579.            - MIN (UNITS_PER_WORD,
  580.               GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref)))));
  581.       ref = SUBREG_REG (ref);
  582.     }
  583.  
  584.   if (GET_CODE (ref) == REG)
  585.     ref = reg_equiv_mem[REGNO (ref)];
  586.  
  587.   if (reload_in_progress)
  588.     base = find_replacement (&XEXP (ref, 0));
  589.   else
  590.     base = XEXP (ref, 0);
  591.  
  592.   if (GET_CODE (base) == PLUS)
  593.     offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
  594.  
  595.   return plus_constant (base, offset);
  596. }
  597.  
  598. /* Subfunction of the following function.  Update the flags of any MEM
  599.    found in part of X.  */
  600.  
  601. static void
  602. alpha_set_memflags_1 (x, in_struct_p, volatile_p, unchanging_p)
  603.      rtx x;
  604.      int in_struct_p, volatile_p, unchanging_p;
  605. {
  606.   int i;
  607.  
  608.   switch (GET_CODE (x))
  609.     {
  610.     case SEQUENCE:
  611.     case PARALLEL:
  612.       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
  613.     alpha_set_memflags_1 (XVECEXP (x, 0, i), in_struct_p, volatile_p,
  614.                   unchanging_p);
  615.       break;
  616.  
  617.     case INSN:
  618.       alpha_set_memflags_1 (PATTERN (x), in_struct_p, volatile_p,
  619.                 unchanging_p);
  620.       break;
  621.  
  622.     case SET:
  623.       alpha_set_memflags_1 (SET_DEST (x), in_struct_p, volatile_p,
  624.                 unchanging_p);
  625.       alpha_set_memflags_1 (SET_SRC (x), in_struct_p, volatile_p,
  626.                 unchanging_p);
  627.       break;
  628.  
  629.     case MEM:
  630.       MEM_IN_STRUCT_P (x) = in_struct_p;
  631.       MEM_VOLATILE_P (x) = volatile_p;
  632.       RTX_UNCHANGING_P (x) = unchanging_p;
  633.       break;
  634.     }
  635. }
  636.  
  637. /* Given INSN, which is either an INSN or a SEQUENCE generated to
  638.    perform a memory operation, look for any MEMs in either a SET_DEST or
  639.    a SET_SRC and copy the in-struct, unchanging, and volatile flags from
  640.    REF into each of the MEMs found.  If REF is not a MEM, don't do
  641.    anything.  */
  642.  
  643. void
  644. alpha_set_memflags (insn, ref)
  645.      rtx insn;
  646.      rtx ref;
  647. {
  648.   /* Note that it is always safe to get these flags, though they won't
  649.      be what we think if REF is not a MEM.  */
  650.   int in_struct_p = MEM_IN_STRUCT_P (ref);
  651.   int volatile_p = MEM_VOLATILE_P (ref);
  652.   int unchanging_p = RTX_UNCHANGING_P (ref);
  653.  
  654.   if (GET_CODE (ref) != MEM
  655.       || (! in_struct_p && ! volatile_p && ! unchanging_p))
  656.     return;
  657.  
  658.   alpha_set_memflags_1 (insn, in_struct_p, volatile_p, unchanging_p);
  659. }
  660.  
  661. /* Try to output insns to set TARGET equal to the constant C if it can be
  662.    done in less than N insns.  Do all computations in MODE.  Returns the place
  663.    where the output has been placed if it can be done and the insns have been
  664.    emitted.  If it would take more than N insns, zero is returned and no
  665.    insns and emitted.  */
  666.  
  667. rtx
  668. alpha_emit_set_const (target, mode, c, n)
  669.      rtx target;
  670.      enum machine_mode mode;
  671.      HOST_WIDE_INT c;
  672.      int n;
  673. {
  674.   HOST_WIDE_INT new = c;
  675.   int i, bits;
  676.   /* Use a pseudo if highly optimizing and still generating RTL.  */
  677.   rtx subtarget
  678.     = (flag_expensive_optimizations && rtx_equal_function_value_matters
  679.        ? 0 : target);
  680.   rtx temp;
  681.  
  682. #if HOST_BITS_PER_WIDE_INT == 64
  683.   /* We are only called for SImode and DImode.  If this is SImode, ensure that
  684.      we are sign extended to a full word.  This does not make any sense when
  685.      cross-compiling on a narrow machine.  */
  686.  
  687.   if (mode == SImode)
  688.     c = (c & 0xffffffff) - 2 * (c & 0x80000000);
  689. #endif
  690.  
  691.   /* If this is a sign-extended 32-bit constant, we can do this in at most
  692.      three insns, so do it if we have enough insns left.  We always have
  693.      a sign-extended 32-bit constant when compiling on a narrow machine. 
  694.      Note that we cannot handle the constant 0x80000000.  */
  695.  
  696.   if ((HOST_BITS_PER_WIDE_INT != 64
  697.        || c >> 31 == -1 || c >> 31 == 0)
  698.       && c != 0x80000000u)
  699.     {
  700.       HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000);
  701.       HOST_WIDE_INT tmp1 = c - low;
  702.       HOST_WIDE_INT high
  703.     = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
  704.       HOST_WIDE_INT extra = 0;
  705.  
  706.       /* If HIGH will be interpreted as negative but the constant is
  707.      positive, we must adjust it to do two ldha insns.  */
  708.  
  709.       if ((high & 0x8000) != 0 && c >= 0)
  710.     {
  711.       extra = 0x4000;
  712.       tmp1 -= 0x40000000;
  713.       high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
  714.     }
  715.  
  716.       if (c == low || (low == 0 && extra == 0))
  717.     return copy_to_suggested_reg (GEN_INT (c), target, mode);
  718.       else if (n >= 2 + (extra != 0))
  719.     {
  720.       temp = copy_to_suggested_reg (GEN_INT (low), subtarget, mode);
  721.  
  722.       if (extra != 0)
  723.         temp = expand_binop (mode, add_optab, temp, GEN_INT (extra << 16),
  724.                  subtarget, 0, OPTAB_WIDEN);
  725.  
  726.       return expand_binop (mode, add_optab, temp, GEN_INT (high << 16),
  727.                    target, 0, OPTAB_WIDEN);
  728.     }
  729.     }
  730.  
  731.   /* If we couldn't do it that way, try some other methods.  But if we have
  732.      no instructions left, don't bother.  Likewise, if this is SImode and
  733.      we can't make pseudos, we can't do anything since the expand_binop
  734.      and expand_unop calls will widen and try to make pseudos.  */
  735.  
  736.   if (n == 1
  737.       || (mode == SImode && ! rtx_equal_function_value_matters))
  738.     return 0;
  739.  
  740. #if HOST_BITS_PER_WIDE_INT == 64
  741.   /* First, see if can load a value into the target that is the same as the
  742.      constant except that all bytes that are 0 are changed to be 0xff.  If we
  743.      can, then we can do a ZAPNOT to obtain the desired constant.  */
  744.  
  745.   for (i = 0; i < 64; i += 8)
  746.     if ((new & ((HOST_WIDE_INT) 0xff << i)) == 0)
  747.       new |= (HOST_WIDE_INT) 0xff << i;
  748.  
  749.   if ((temp = alpha_emit_set_const (subtarget, mode, new, n - 1)) != 0)
  750.     return expand_binop (mode, and_optab, temp, GEN_INT (c | ~ new),
  751.              target, 0, OPTAB_WIDEN);
  752. #endif
  753.  
  754.   /* Next, see if we can load a related constant and then shift and possibly
  755.      negate it to get the constant we want.  Try this once each increasing
  756.      numbers of insns.  */
  757.  
  758.   for (i = 1; i < n; i++)
  759.     {
  760.       /* First try complementing.  */
  761.       if ((temp = alpha_emit_set_const (subtarget, mode, ~ c, i)) != 0)
  762.     return expand_unop (mode, one_cmpl_optab, temp, target, 0);
  763.  
  764.       /* Next try to form a constant and do a left shift.  We can do this
  765.      if some low-order bits are zero; the exact_log2 call below tells
  766.      us that information.  The bits we are shifting out could be any
  767.      value, but here we'll just try the 0- and sign-extended forms of
  768.      the constant.  To try to increase the chance of having the same
  769.      constant in more than one insn, start at the highest number of
  770.      bits to shift, but try all possibilities in case a ZAPNOT will
  771.      be useful.  */
  772.  
  773.       if ((bits = exact_log2 (c & - c)) > 0)
  774.     for (; bits > 0; bits--)
  775.       if ((temp = (alpha_emit_set_const
  776.                (subtarget, mode,
  777.             (unsigned HOST_WIDE_INT) c >> bits, i))) != 0
  778.           || ((temp = (alpha_emit_set_const
  779.               (subtarget, mode,
  780.                ((unsigned HOST_WIDE_INT) c) >> bits, i)))
  781.           != 0))
  782.         return expand_binop (mode, ashl_optab, temp, GEN_INT (bits),
  783.                  target, 0, OPTAB_WIDEN);
  784.  
  785.       /* Now try high-order zero bits.  Here we try the shifted-in bits as
  786.      all zero and all ones.  */
  787.  
  788.       if ((bits = HOST_BITS_PER_WIDE_INT - floor_log2 (c) - 1) > 0)
  789.     for (; bits > 0; bits--)
  790.       if ((temp = alpha_emit_set_const (subtarget, mode,
  791.                         c << bits, i)) != 0
  792.           || ((temp = (alpha_emit_set_const
  793.                (subtarget, mode,
  794.                 ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
  795.                 i)))
  796.           != 0))
  797.         return expand_binop (mode, lshr_optab, temp, GEN_INT (bits),
  798.                  target, 0, OPTAB_WIDEN);
  799.  
  800.       /* Now try high-order 1 bits.  We get that with a sign-extension.
  801.      But one bit isn't enough here.  */
  802.       
  803.       if ((bits = HOST_BITS_PER_WIDE_INT - floor_log2 (~ c) - 2) > 0)
  804.     for (; bits > 0; bits--)
  805.       if ((temp = alpha_emit_set_const (subtarget, mode,
  806.                         c << bits, i)) != 0
  807.           || ((temp = (alpha_emit_set_const
  808.                (subtarget, mode,
  809.                 ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
  810.                 i)))
  811.           != 0))
  812.         return expand_binop (mode, ashr_optab, temp, GEN_INT (bits),
  813.                  target, 0, OPTAB_WIDEN);
  814.     }
  815.  
  816.   return 0;
  817. }
  818.  
  819. /* Adjust the cost of a scheduling dependency.  Return the new cost of
  820.    a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
  821.  
  822. int
  823. alpha_adjust_cost (insn, link, dep_insn, cost)
  824.      rtx insn;
  825.      rtx link;
  826.      rtx dep_insn;
  827.      int cost;
  828. {
  829.   rtx set;
  830.  
  831.   /* If the dependence is an anti-dependence, there is no cost.  For an
  832.      output dependence, there is sometimes a cost, but it doesn't seem
  833.      worth handling those few cases.  */
  834.  
  835.   if (REG_NOTE_KIND (link) != 0)
  836.     return 0;
  837.  
  838.   /* If INSN is a store insn and DEP_INSN is setting the data being stored,
  839.      we can sometimes lower the cost.  */
  840.  
  841.   if (recog_memoized (insn) >= 0 && get_attr_type (insn) == TYPE_ST
  842.       && (set = single_set (dep_insn)) != 0
  843.       && GET_CODE (PATTERN (insn)) == SET
  844.       && rtx_equal_p (SET_DEST (set), SET_SRC (PATTERN (insn))))
  845.     switch (get_attr_type (dep_insn))
  846.       {
  847.       case TYPE_LD:
  848.     /* No savings here.  */
  849.     return cost;
  850.  
  851.       case TYPE_IMULL:
  852.       case TYPE_IMULQ:
  853.     /* In these cases, we save one cycle.  */
  854.     return cost - 2;
  855.  
  856.       default:
  857.     /* In all other cases, we save two cycles.  */
  858.     return MAX (0, cost - 4);
  859.       }
  860.  
  861.   /* Another case that needs adjustment is an arithmetic or logical
  862.      operation.  It's cost is usually one cycle, but we default it to
  863.      two in the MD file.  The only case that it is actually two is
  864.      for the address in loads and stores.  */
  865.  
  866.   if (recog_memoized (dep_insn) >= 0
  867.       && get_attr_type (dep_insn) == TYPE_IADDLOG)
  868.     switch (get_attr_type (insn))
  869.       {
  870.       case TYPE_LD:
  871.       case TYPE_ST:
  872.     return cost;
  873.  
  874.       default:
  875.     return 2;
  876.       }
  877.  
  878.   /* The final case is when a compare feeds into an integer branch.  The cost
  879.      is only one cycle in that case.  */
  880.  
  881.   if (recog_memoized (dep_insn) >= 0
  882.       && get_attr_type (dep_insn) == TYPE_ICMP
  883.       && recog_memoized (insn) >= 0
  884.       && get_attr_type (insn) == TYPE_IBR)
  885.     return 2;
  886.  
  887.   /* Otherwise, return the default cost. */
  888.  
  889.   return cost;
  890. }
  891.  
  892. /* Print an operand.  Recognize special options, documented below.  */
  893.  
  894. void
  895. print_operand (file, x, code)
  896.     FILE *file;
  897.     rtx x;
  898.     char code;
  899. {
  900.   int i;
  901.  
  902.   switch (code)
  903.     {
  904.     case 'r':
  905.       /* If this operand is the constant zero, write it as "$31".  */
  906.       if (GET_CODE (x) == REG)
  907.     fprintf (file, "%s", reg_names[REGNO (x)]);
  908.       else if (x == CONST0_RTX (GET_MODE (x)))
  909.     fprintf (file, "$31");
  910.       else
  911.     output_operand_lossage ("invalid %%r value");
  912.  
  913.       break;
  914.  
  915.     case 'R':
  916.       /* Similar, but for floating-point.  */
  917.       if (GET_CODE (x) == REG)
  918.     fprintf (file, "%s", reg_names[REGNO (x)]);
  919.       else if (x == CONST0_RTX (GET_MODE (x)))
  920.     fprintf (file, "$f31");
  921.       else
  922.     output_operand_lossage ("invalid %%R value");
  923.  
  924.       break;
  925.  
  926.     case 'N':
  927.       /* Write the 1's complement of a constant.  */
  928.       if (GET_CODE (x) != CONST_INT)
  929.     output_operand_lossage ("invalid %%N value");
  930.  
  931.       fprintf (file, "%ld", ~ INTVAL (x));
  932.       break;
  933.  
  934.     case 'P':
  935.       /* Write 1 << C, for a constant C.  */
  936.       if (GET_CODE (x) != CONST_INT)
  937.     output_operand_lossage ("invalid %%P value");
  938.  
  939.       fprintf (file, "%ld", (HOST_WIDE_INT) 1 << INTVAL (x));
  940.       break;
  941.  
  942.     case 'h':
  943.       /* Write the high-order 16 bits of a constant, sign-extended.  */
  944.       if (GET_CODE (x) != CONST_INT)
  945.     output_operand_lossage ("invalid %%h value");
  946.  
  947.       fprintf (file, "%ld", INTVAL (x) >> 16);
  948.       break;
  949.  
  950.     case 'L':
  951.       /* Write the low-order 16 bits of a constant, sign-extended.  */
  952.       if (GET_CODE (x) != CONST_INT)
  953.     output_operand_lossage ("invalid %%L value");
  954.  
  955.       fprintf (file, "%ld", (INTVAL (x) & 0xffff) - 2 * (INTVAL (x) & 0x8000));
  956.       break;
  957.  
  958.     case 'm':
  959.       /* Write mask for ZAP insn.  */
  960.       if (GET_CODE (x) == CONST_DOUBLE)
  961.     {
  962.       HOST_WIDE_INT mask = 0;
  963.       HOST_WIDE_INT value;
  964.  
  965.       value = CONST_DOUBLE_LOW (x);
  966.       for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
  967.            i++, value >>= 8)
  968.         if (value & 0xff)
  969.           mask |= (1 << i);
  970.  
  971.       value = CONST_DOUBLE_HIGH (x);
  972.       for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
  973.            i++, value >>= 8)
  974.         if (value & 0xff)
  975.           mask |= (1 << (i + sizeof (int)));
  976.  
  977.       fprintf (file, "%ld", mask & 0xff);
  978.     }
  979.  
  980.       else if (GET_CODE (x) == CONST_INT)
  981.     {
  982.       HOST_WIDE_INT mask = 0, value = INTVAL (x);
  983.  
  984.       for (i = 0; i < 8; i++, value >>= 8)
  985.         if (value & 0xff)
  986.           mask |= (1 << i);
  987.  
  988.       fprintf (file, "%ld", mask);
  989.     }
  990.       else
  991.     output_operand_lossage ("invalid %%m value");
  992.       break;
  993.  
  994.     case 'M':
  995.       /* 'b', 'w', or 'l' as the value of the constant.  */
  996.       if (GET_CODE (x) != CONST_INT
  997.       || (INTVAL (x) != 8 && INTVAL (x) != 16 && INTVAL (x) != 32))
  998.     output_operand_lossage ("invalid %%M value");
  999.  
  1000.       fprintf (file, "%s",
  1001.            INTVAL (x) == 8 ? "b" : INTVAL (x) == 16 ? "w" : "l");
  1002.       break;
  1003.  
  1004.     case 'U':
  1005.       /* Similar, except do it from the mask.  */
  1006.       if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xff)
  1007.     fprintf (file, "b");
  1008.       else if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xffff)
  1009.     fprintf (file, "w");
  1010. #if HOST_BITS_PER_WIDE_INT == 32
  1011.       else if (GET_CODE (x) == CONST_DOUBLE
  1012.            && CONST_DOUBLE_HIGH (x) == 0
  1013.            && CONST_DOUBLE_LOW (x) == -1)
  1014.     fprintf (file, "l");
  1015. #else
  1016.       else if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0xffffffff)
  1017.     fprintf (file, "l");
  1018. #endif
  1019.       else
  1020.     output_operand_lossage ("invalid %%U value");
  1021.       break;
  1022.  
  1023.     case 's':
  1024.       /* Write the constant value divided by 8.  */
  1025.       if (GET_CODE (x) != CONST_INT
  1026.       && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
  1027.       && (INTVAL (x) & 7) != 8)
  1028.     output_operand_lossage ("invalid %%s value");
  1029.  
  1030.       fprintf (file, "%ld", INTVAL (x) / 8);
  1031.       break;
  1032.  
  1033.     case 'S':
  1034.       /* Same, except compute (64 - c) / 8 */
  1035.  
  1036.       if (GET_CODE (x) != CONST_INT
  1037.       && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
  1038.       && (INTVAL (x) & 7) != 8)
  1039.     output_operand_lossage ("invalid %%s value");
  1040.  
  1041.       fprintf (file, "%ld", (64 - INTVAL (x)) / 8);
  1042.       break;
  1043.  
  1044.     case 'C':
  1045.       /* Write out comparison name.  */
  1046.       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
  1047.     output_operand_lossage ("invalid %%C value");
  1048.  
  1049.       if (GET_CODE (x) == LEU)
  1050.     fprintf (file, "ule");
  1051.       else if (GET_CODE (x) == LTU)
  1052.     fprintf (file, "ult");
  1053.       else
  1054.     fprintf (file, "%s", GET_RTX_NAME (GET_CODE (x)));
  1055.       break;
  1056.  
  1057.     case 'D':
  1058.       /* Similar, but write reversed code.  We can't get an unsigned code
  1059.      here.  */
  1060.       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
  1061.     output_operand_lossage ("invalid %%D value");
  1062.  
  1063.       fprintf (file, "%s", GET_RTX_NAME (reverse_condition (GET_CODE (x))));
  1064.       break;
  1065.  
  1066.     case 'c':
  1067.       /* Similar to `c', but swap.  We can't get unsigned here either.  */
  1068.       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
  1069.     output_operand_lossage ("invalid %%D value");
  1070.  
  1071.       fprintf (file, "%s", GET_RTX_NAME (swap_condition (GET_CODE (x))));
  1072.       break;
  1073.  
  1074.     case 'd':
  1075.       /* Similar, but reverse and swap.  We can't get unsigned here either.  */
  1076.       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
  1077.     output_operand_lossage ("invalid %%D value");
  1078.  
  1079.       fprintf (file, "%s",
  1080.            GET_RTX_NAME (swap_condition (reverse_condition ((GET_CODE (x))))));
  1081.       break;
  1082.  
  1083.     case 'E':
  1084.       /* Write the divide or modulus operator.  */
  1085.       switch (GET_CODE (x))
  1086.     {
  1087.     case DIV:
  1088.       fprintf (file, "div%s", GET_MODE (x) == SImode ? "l" : "q");
  1089.       break;
  1090.     case UDIV:
  1091.       fprintf (file, "div%su", GET_MODE (x) == SImode ? "l" : "q");
  1092.       break;
  1093.     case MOD:
  1094.       fprintf (file, "rem%s", GET_MODE (x) == SImode ? "l" : "q");
  1095.       break;
  1096.     case UMOD:
  1097.       fprintf (file, "rem%su", GET_MODE (x) == SImode ? "l" : "q");
  1098.       break;
  1099.     default:
  1100.       output_operand_lossage ("invalid %%E value");
  1101.       break;
  1102.     }
  1103.       break;
  1104.  
  1105.     case 'A':
  1106.       /* Write "_u" for unaligned access.  */
  1107.       if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
  1108.     fprintf (file, "_u");
  1109.       break;
  1110.  
  1111.     case 0:
  1112.       if (GET_CODE (x) == REG)
  1113.     fprintf (file, "%s", reg_names[REGNO (x)]);
  1114.       else if (GET_CODE (x) == MEM)
  1115.     output_address (XEXP (x, 0));
  1116.       else
  1117.     output_addr_const (file, x);
  1118.       break;
  1119.  
  1120.     default:
  1121.       output_operand_lossage ("invalid %%xn code");
  1122.     }
  1123. }
  1124.  
  1125. /* Do what is necessary for `va_start'.  The argument is ignored;
  1126.    We look at the current function to determine if stdarg or varargs
  1127.    is used and fill in an initial va_list.  A pointer to this constructor
  1128.    is returned.  */
  1129.  
  1130. struct rtx_def *
  1131. alpha_builtin_saveregs (arglist)
  1132.      tree arglist;
  1133. {
  1134.   rtx block, addr, argsize;
  1135.   tree fntype = TREE_TYPE (current_function_decl);
  1136.   int stdarg = (TYPE_ARG_TYPES (fntype) != 0
  1137.         && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
  1138.             != void_type_node));
  1139.  
  1140.   /* Compute the current position into the args, taking into account
  1141.      both registers and memory.  Both of these are already included in
  1142.      current_function_args_info.  */
  1143.  
  1144.   argsize = GEN_INT (current_function_args_info * UNITS_PER_WORD);
  1145.  
  1146.   /* SETUP_INCOMING_VARARGS moves the starting address base up by 48,
  1147.      storing fp arg registers in the first 48 bytes, and the integer arg
  1148.      registers in the next 48 bytes.  This is only done, however, if any
  1149.      integer registers need to be stored.
  1150.  
  1151.      If no integer registers need be stored, then we must subtract 48 in
  1152.      order to account for the integer arg registers which are counted in
  1153.      argsize above, but which are not actually stored on the stack.  */
  1154.  
  1155.   addr = (current_function_args_info <= 5 + stdarg
  1156.       ? plus_constant (virtual_incoming_args_rtx, 6 * UNITS_PER_WORD)
  1157.       : plus_constant (virtual_incoming_args_rtx, - (6 * UNITS_PER_WORD)));
  1158.  
  1159.   addr = force_operand (addr, NULL_RTX);
  1160.  
  1161.   /* Allocate the va_list constructor */
  1162.   block = assign_stack_local (BLKmode, 2 * UNITS_PER_WORD, BITS_PER_WORD);
  1163.   RTX_UNCHANGING_P (block) = 1;
  1164.   RTX_UNCHANGING_P (XEXP (block, 0)) = 1;
  1165.  
  1166.   /* Store the address of the first integer register in the __base member.
  1167.      Note that our offsets are correct for both 32- and 64-bit pointers
  1168.      due to the alignment of the __offset field (a long).  */
  1169.  
  1170. #ifdef POINTERS_EXTEND_UNSIGNED
  1171.   addr = convert_memory_address (ptr_mode, addr);
  1172. #endif
  1173.  
  1174.   emit_move_insn (change_address (block, ptr_mode, XEXP (block, 0)), addr);
  1175.  
  1176.   /* Store the argsize as the __va_offset member.  */
  1177.   emit_move_insn (change_address (block, ptr_mode,
  1178.                   plus_constant (XEXP (block, 0),
  1179.                          GET_MODE_SIZE (ptr_mode))),
  1180.           force_operand (argsize, NULL_RTX));
  1181.  
  1182.   /* Return the address of the va_list constructor, but don't put it in a
  1183.      register.  Doing so would fail when not optimizing and produce worse
  1184.      code when optimizing.  */
  1185.   return XEXP (block, 0);
  1186. }
  1187.  
  1188. /* This page contains routines that are used to determine what the function
  1189.    prologue and epilogue code will do and write them out.  */
  1190.  
  1191. /* Compute the size of the save area in the stack.  */
  1192.  
  1193. int
  1194. alpha_sa_size ()
  1195. {
  1196.   int size = 0;
  1197.   int i;
  1198.  
  1199.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1200.     if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i])
  1201.       size++;
  1202.  
  1203.   /* If some registers were saved but not reg 26, reg 26 must also
  1204.      be saved, so leave space for it.  */
  1205.   if (size != 0 && ! regs_ever_live[26])
  1206.     size++;
  1207.  
  1208.   /* Our size must be even (multiple of 16 bytes).  */
  1209.   if (size & 1)
  1210.     size ++;
  1211.  
  1212.   return size * 8;
  1213. }
  1214.  
  1215. /* Return 1 if this function can directly return via $26.  */
  1216.  
  1217. int
  1218. direct_return ()
  1219. {
  1220.   return (reload_completed && alpha_sa_size () == 0
  1221.       && get_frame_size () == 0
  1222.       && current_function_outgoing_args_size == 0
  1223.       && current_function_pretend_args_size == 0);
  1224. }
  1225.  
  1226. /* Write a version stamp.  Don't write anything if we are running as a
  1227.    cross-compiler.  Otherwise, use the versions in /usr/include/stamp.h.  */
  1228.  
  1229. #if !defined(CROSS_COMPILE) && !defined(_WIN32)
  1230. #include <stamp.h>
  1231. #endif
  1232.  
  1233. void
  1234. alpha_write_verstamp (file)
  1235.      FILE *file;
  1236. {
  1237. #ifdef MS_STAMP
  1238.   char *p;
  1239.  
  1240.   fprintf (file, "\t.verstamp %d %d ", MS_STAMP, LS_STAMP);
  1241.   for (p = version_string; *p != ' ' && *p != 0; p++)
  1242.     fprintf (file, "%c", *p == '.' ? ' ' : *p);
  1243.   fprintf (file, "\n");
  1244. #endif
  1245. }
  1246.  
  1247. /* Write code to add constant C to register number IN_REG (possibly 31)
  1248.    and put the result into OUT_REG.  Use TEMP_REG as a scratch register;
  1249.    usually this will be OUT_REG, but should not be if OUT_REG is 
  1250.    STACK_POINTER_REGNUM, since it must be updated in a single instruction.
  1251.    Write the code to FILE.  */
  1252.  
  1253. static void
  1254. add_long_const (file, c, in_reg, out_reg, temp_reg)
  1255.      FILE *file;
  1256.      HOST_WIDE_INT c;
  1257.      int in_reg, out_reg, temp_reg;
  1258. {
  1259.   HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000);
  1260.   HOST_WIDE_INT tmp1 = c - low;
  1261.   HOST_WIDE_INT high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
  1262.   HOST_WIDE_INT extra = 0;
  1263.  
  1264.   /* We don't have code to write out constants larger than 32 bits.  */
  1265. #if HOST_BITS_PER_LONG_INT == 64
  1266.   if ((unsigned HOST_WIDE_INT) c >> 32 != 0)
  1267.     abort ();
  1268. #endif
  1269.  
  1270.   /* If HIGH will be interpreted as negative, we must adjust it to do two
  1271.      ldha insns.  Note that we will never be building a negative constant
  1272.      here.  */
  1273.  
  1274.   if (high & 0x8000)
  1275.     {
  1276.       extra = 0x4000;
  1277.       tmp1 -= 0x40000000;
  1278.       high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
  1279.     }
  1280.  
  1281.   if (low != 0)
  1282.     {
  1283.       int result_reg = (extra == 0 && high == 0) ? out_reg : temp_reg;
  1284.  
  1285.       if (low >= 0 && low < 255)
  1286.     fprintf (file, "\taddq $%d,%d,$%d\n", in_reg, low, result_reg);
  1287.       else
  1288.     fprintf (file, "\tlda $%d,%d($%d)\n", result_reg, low, in_reg);
  1289.  
  1290.       in_reg = result_reg;
  1291.     }
  1292.  
  1293.   if (extra)
  1294.     {
  1295.       int result_reg = (high == 0) ? out_reg : temp_reg;
  1296.  
  1297.       fprintf (file, "\tldah $%d,%d($%d)\n", result_reg, extra, in_reg);
  1298.       in_reg = result_reg;
  1299.     }
  1300.  
  1301.   if (high)
  1302.     fprintf (file, "\tldah $%d,%d($%d)\n", out_reg, high, in_reg);
  1303. }
  1304.  
  1305. /* Write function prologue.  */
  1306.  
  1307. void
  1308. output_prolog (file, size)
  1309.      FILE *file;
  1310.      int size;
  1311. {
  1312.   HOST_WIDE_INT out_args_size
  1313.     = ALPHA_ROUND (current_function_outgoing_args_size);
  1314.   HOST_WIDE_INT sa_size = alpha_sa_size ();
  1315.   HOST_WIDE_INT frame_size
  1316.     = (out_args_size + sa_size
  1317.        + ALPHA_ROUND (size + current_function_pretend_args_size));
  1318.   HOST_WIDE_INT reg_offset = out_args_size;
  1319.   HOST_WIDE_INT start_reg_offset = reg_offset;
  1320.   HOST_WIDE_INT actual_start_reg_offset = start_reg_offset;
  1321.   int int_reg_save_area_size = 0;
  1322.   rtx insn;
  1323.   unsigned reg_mask = 0;
  1324.   int i;
  1325.  
  1326.   /* Ecoff can handle multiple .file directives, so put out file and lineno.
  1327.      We have to do that before the .ent directive as we cannot switch
  1328.      files within procedures with native ecoff because line numbers are
  1329.      linked to procedure descriptors.
  1330.      Outputting the lineno helps debugging of one line functions as they
  1331.      would otherwise get no line number at all. Please note that we would
  1332.      like to put out last_linenum from final.c, but it is not accessible.  */
  1333.  
  1334.   if (write_symbols == SDB_DEBUG)
  1335.     {
  1336.       ASM_OUTPUT_SOURCE_FILENAME (file,
  1337.                   DECL_SOURCE_FILE (current_function_decl));
  1338.       if (debug_info_level != DINFO_LEVEL_TERSE)
  1339.         ASM_OUTPUT_SOURCE_LINE (file,
  1340.                 DECL_SOURCE_LINE (current_function_decl));
  1341.     }
  1342.  
  1343.   /* The assembly language programmer's guide states that the second argument
  1344.      to the .ent directive, the lex_level, is ignored by the assembler,
  1345.      so we might as well omit it.  */
  1346.      
  1347.   fprintf (file, "\t.ent ");
  1348.   assemble_name (file, alpha_function_name);
  1349.   fprintf (file, "\n");
  1350.   ASM_OUTPUT_LABEL (file, alpha_function_name);
  1351.   inside_function = TRUE;
  1352.  
  1353.   /* Set up offsets to alpha virtual arg/local debugging pointer.  */
  1354.  
  1355.   alpha_auto_offset = -frame_size + current_function_pretend_args_size;
  1356.   alpha_arg_offset = -frame_size + 48;
  1357.  
  1358.   /* If we need a GP (we have a LDSYM insn or a CALL_INSN), load it first. 
  1359.      Even if we are a static function, we still need to do this in case
  1360.      our address is taken and passed to something like qsort.
  1361.  
  1362.      We never need a GP for Windows/NT.  */
  1363.  
  1364.   alpha_function_needs_gp = 0;
  1365.   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  1366.     if ((GET_CODE (insn) == CALL_INSN)
  1367.     || (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  1368.         && GET_CODE (PATTERN (insn)) != USE
  1369.         && GET_CODE (PATTERN (insn)) != CLOBBER
  1370.         && (get_attr_type (insn) == TYPE_LDSYM
  1371.         || get_attr_type (insn) == TYPE_ISUBR)))
  1372.       {
  1373.     alpha_function_needs_gp = 1;
  1374.     break;
  1375.       }
  1376.  
  1377.   if (WINDOWS_NT == 0)
  1378.     {
  1379.       if (alpha_function_needs_gp)
  1380.     fprintf (file, "\tldgp $29,0($27)\n");
  1381.  
  1382.       /* Put a label after the GP load so we can enter the function at it.  */
  1383.       assemble_name (file, alpha_function_name);
  1384.       fprintf (file, "..ng:\n");
  1385.     }
  1386.  
  1387.   /* Adjust the stack by the frame size.  If the frame size is > 4096
  1388.      bytes, we need to be sure we probe somewhere in the first and last
  1389.      4096 bytes (we can probably get away without the latter test) and
  1390.      every 8192 bytes in between.  If the frame size is > 32768, we
  1391.      do this in a loop.  Otherwise, we generate the explicit probe
  1392.      instructions. 
  1393.  
  1394.      Note that we are only allowed to adjust sp once in the prologue.  */
  1395.  
  1396.   if (frame_size < 32768)
  1397.     {
  1398.       if (frame_size > 4096)
  1399.     {
  1400.       int probed = 4096;
  1401.  
  1402.       fprintf (file, "\tstq $31,-%d($30)\n", probed);
  1403.  
  1404.       while (probed + 8192 < frame_size)
  1405.         fprintf (file, "\tstq $31,-%d($30)\n", probed += 8192);
  1406.  
  1407.       /* We only have to do this probe if we aren't saving registers.  */
  1408.       if (sa_size == 0 && probed + 4096 < frame_size)
  1409.         fprintf (file, "\tstq $31,-%d($30)\n", frame_size);
  1410.     }
  1411.  
  1412.       if (frame_size != 0)
  1413.     fprintf (file, "\tlda $30,-%d($30)\n", frame_size);
  1414.     }
  1415.   else
  1416.     {
  1417.       /* Here we generate code to set R4 to SP + 4096 and set R5 to the
  1418.      number of 8192 byte blocks to probe.  We then probe each block
  1419.      in the loop and then set SP to the proper location.  If the
  1420.      amount remaining is > 4096, we have to do one more probe if we
  1421.      are not saving any registers.  */
  1422.  
  1423.       HOST_WIDE_INT blocks = (frame_size + 4096) / 8192;
  1424.       HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192;
  1425.  
  1426.       add_long_const (file, blocks, 31, 5, 5);
  1427.  
  1428.       fprintf (file, "\tlda $4,4096($30)\n");
  1429.  
  1430.       assemble_name (file, alpha_function_name);
  1431.       fprintf (file, "..sc:\n");
  1432.  
  1433.       fprintf (file, "\tstq $31,-8192($4)\n");
  1434.       fprintf (file, "\tsubq $5,1,$5\n");
  1435.       fprintf (file, "\tlda $4,-8192($4)\n");
  1436.  
  1437.       fprintf (file, "\tbne $5,");
  1438.       assemble_name (file, alpha_function_name);
  1439.       fprintf (file, "..sc\n");
  1440.  
  1441.       if (leftover > 4096 && sa_size == 0)
  1442.     fprintf (file, "\tstq $31,-%d($4)\n", leftover);
  1443.  
  1444.       fprintf (file, "\tlda $30,-%d($4)\n", leftover);
  1445.     }
  1446.  
  1447.   /* Describe our frame.  */
  1448.   fprintf (file, "\t.frame $%d,%d,$26,%d\n", 
  1449.        (frame_pointer_needed
  1450.         ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM),
  1451.        frame_size, current_function_pretend_args_size);
  1452.     
  1453.   /* Save register 26 if any other register needs to be saved.  */
  1454.   if (sa_size != 0)
  1455.     {
  1456.       reg_mask |= 1 << 26;
  1457.       fprintf (file, "\tstq $26,%d($30)\n", reg_offset);
  1458.       reg_offset += 8;
  1459.       int_reg_save_area_size += 8;
  1460.     }
  1461.  
  1462.   /* Now save any other used integer registers required to be saved.  */
  1463.   for (i = 0; i < 32; i++)
  1464.     if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i] && i != 26)
  1465.       {
  1466.     reg_mask |= 1 << i;
  1467.     fprintf (file, "\tstq $%d,%d($30)\n", i, reg_offset);
  1468.     reg_offset += 8;
  1469.     int_reg_save_area_size += 8;
  1470.       }
  1471.  
  1472.   /* Print the register mask and do floating-point saves.  */
  1473.   if (reg_mask)
  1474.     fprintf (file, "\t.mask 0x%x,%d\n", reg_mask,
  1475.          actual_start_reg_offset - frame_size);
  1476.  
  1477.   start_reg_offset = reg_offset;
  1478.   reg_mask = 0;
  1479.  
  1480.   for (i = 0; i < 32; i++)
  1481.     if (! fixed_regs[i + 32] && ! call_used_regs[i + 32]
  1482.     && regs_ever_live[i + 32])
  1483.       {
  1484.     reg_mask |= 1 << i;
  1485.     fprintf (file, "\tstt $f%d,%d($30)\n", i, reg_offset);
  1486.     reg_offset += 8;
  1487.       }
  1488.  
  1489.   /* Print the floating-point mask, if we've saved any fp register.  */
  1490.   if (reg_mask)
  1491.     fprintf (file, "\t.fmask 0x%x,%d\n", reg_mask,
  1492.          actual_start_reg_offset - frame_size + int_reg_save_area_size);
  1493.  
  1494.   /* If we need a frame pointer, set it from the stack pointer.  Note that
  1495.      this must always be the last instruction in the prologue.  */
  1496.   if (frame_pointer_needed)
  1497.     fprintf (file, "\tbis $30,$30,$15\n");
  1498.  
  1499.   /* End the prologue and say if we used gp.  */
  1500.   fprintf (file, "\t.prologue %d\n", alpha_function_needs_gp);
  1501. }
  1502.  
  1503. /* Write function epilogue.  */
  1504.  
  1505. void
  1506. output_epilog (file, size)
  1507.      FILE *file;
  1508.      int size;
  1509. {
  1510.   rtx insn = get_last_insn ();
  1511.   HOST_WIDE_INT out_args_size
  1512.     = ALPHA_ROUND (current_function_outgoing_args_size);
  1513.   HOST_WIDE_INT sa_size = alpha_sa_size ();
  1514.   HOST_WIDE_INT frame_size
  1515.     = (out_args_size + sa_size
  1516.        + ALPHA_ROUND (size + current_function_pretend_args_size));
  1517.   HOST_WIDE_INT reg_offset = out_args_size;
  1518.   HOST_WIDE_INT frame_size_from_reg_save = frame_size - reg_offset;
  1519.   int restore_fp
  1520.     = frame_pointer_needed && regs_ever_live[HARD_FRAME_POINTER_REGNUM];
  1521.   int i;
  1522.  
  1523.   /* If the last insn was a BARRIER, we don't have to write anything except
  1524.      the .end pseudo-op.  */
  1525.   if (GET_CODE (insn) == NOTE)
  1526.     insn = prev_nonnote_insn (insn);
  1527.   if (insn == 0 || GET_CODE (insn) != BARRIER)
  1528.     {
  1529.       int fp_offset = 0;
  1530.  
  1531.       /* If we have a frame pointer, restore SP from it.  */
  1532.       if (frame_pointer_needed)
  1533.     fprintf (file, "\tbis $15,$15,$30\n");
  1534.  
  1535.       /* Restore all the registers, starting with the return address
  1536.      register.  */
  1537.       if (sa_size != 0)
  1538.     {
  1539.       fprintf (file, "\tldq $26,%d($30)\n", reg_offset);
  1540.       reg_offset += 8;
  1541.     }
  1542.  
  1543.       /* Now restore any other used integer registers that that we saved,
  1544.      except for FP if it is being used as FP, since it must be
  1545.      restored last.  */
  1546.  
  1547.       for (i = 0; i < 32; i++)
  1548.     if (! fixed_regs[i] && ! call_used_regs[i] && regs_ever_live[i]
  1549.         && i != 26)
  1550.       {
  1551.         if (i == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed)
  1552.           fp_offset = reg_offset;
  1553.         else
  1554.           fprintf (file, "\tldq $%d,%d($30)\n", i, reg_offset);
  1555.         reg_offset += 8;
  1556.       }
  1557.  
  1558.       for (i = 0; i < 32; i++)
  1559.     if (! fixed_regs[i + 32] && ! call_used_regs[i + 32]
  1560.         && regs_ever_live[i + 32])
  1561.       {
  1562.         fprintf (file, "\tldt $f%d,%d($30)\n", i, reg_offset);
  1563.         reg_offset += 8;
  1564.       }
  1565.  
  1566.       /* If the stack size is large and we have a frame pointer, compute the
  1567.      size of the stack into a register because the old FP restore, stack
  1568.      pointer adjust, and return are required to be consecutive
  1569.      instructions.   */
  1570.       if (frame_size > 32767 && restore_fp)
  1571.     add_long_const (file, frame_size, 31, 1, 1);
  1572.  
  1573.       /* If we needed a frame pointer and we have to restore it, do it
  1574.      now.  This must be done in one instruction immediately
  1575.      before the SP update.  */
  1576.       if (restore_fp && fp_offset)
  1577.     fprintf (file, "\tldq $15,%d($30)\n", fp_offset);
  1578.  
  1579.       /* Now update the stack pointer, if needed.  Only one instruction must
  1580.      modify the stack pointer.  It must be the last instruction in the
  1581.      sequence and must be an ADDQ or LDA instruction.  If the frame
  1582.      pointer was loaded above, we may only put one instruction here.  */
  1583.  
  1584.       if (frame_size > 32768 && restore_fp)
  1585.     fprintf  (file, "\taddq $1,$30,$30\n");
  1586.       else
  1587.     add_long_const (file, frame_size, 30, 30, 1);
  1588.  
  1589.       /* Finally return to the caller.  */
  1590.       fprintf (file, "\tret $31,($26),1\n");
  1591.     }
  1592.  
  1593.   /* End the function.  */
  1594.   fprintf (file, "\t.end ");
  1595.   assemble_name (file, alpha_function_name);
  1596.   fprintf (file, "\n");
  1597.   inside_function = FALSE;
  1598.  
  1599.   /* Show that we know this function if it is called again.  */
  1600.   SYMBOL_REF_FLAG (XEXP (DECL_RTL (current_function_decl), 0)) = 1;
  1601. }
  1602.  
  1603. /* Debugging support.  */
  1604.  
  1605. #include "gstab.h"
  1606.  
  1607. /* Count the number of sdb related labels are generated (to find block
  1608.    start and end boundaries).  */
  1609.  
  1610. int sdb_label_count = 0;
  1611.  
  1612. /* Next label # for each statement.  */
  1613.  
  1614. static int sym_lineno = 0;
  1615.  
  1616. /* Count the number of .file directives, so that .loc is up to date.  */
  1617.  
  1618. static int num_source_filenames = 0;
  1619.  
  1620. /* Name of the file containing the current function.  */
  1621.  
  1622. static char *current_function_file = "";
  1623.  
  1624. /* Offsets to alpha virtual arg/local debugging pointers.  */
  1625.  
  1626. long alpha_arg_offset;
  1627. long alpha_auto_offset;
  1628.  
  1629. /* Emit a new filename to a stream.  */
  1630.  
  1631. void
  1632. alpha_output_filename (stream, name)
  1633.      FILE *stream;
  1634.      char *name;
  1635. {
  1636.   static int first_time = TRUE;
  1637.   char ltext_label_name[100];
  1638.  
  1639.   if (first_time)
  1640.     {
  1641.       first_time = FALSE;
  1642.       ++num_source_filenames;
  1643.       current_function_file = name;
  1644.       fprintf (stream, "\t.file\t%d ", num_source_filenames);
  1645.       output_quoted_string (stream, name);
  1646.       fprintf (stream, "\n");
  1647.       if (!TARGET_GAS && write_symbols == DBX_DEBUG)
  1648.     fprintf (stream, "\t#@stabs\n");
  1649.     }
  1650.  
  1651.   else if (!TARGET_GAS && write_symbols == DBX_DEBUG)
  1652.     {
  1653.       ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
  1654.       fprintf (stream, "%s ", ASM_STABS_OP);
  1655.       output_quoted_string (stream, name);
  1656.       fprintf (stream, ",%d,0,0,%s\n", N_SOL, <ext_label_name[1]);
  1657.     }
  1658.  
  1659.   else if (name != current_function_file
  1660.       && strcmp (name, current_function_file) != 0)
  1661.     {
  1662.       if (inside_function && ! TARGET_GAS)
  1663.     fprintf (stream, "\t#.file\t%d ", num_source_filenames);
  1664.       else
  1665.     {
  1666.       ++num_source_filenames;
  1667.       current_function_file = name;
  1668.       fprintf (stream, "\t.file\t%d ", num_source_filenames);
  1669.     }
  1670.  
  1671.       output_quoted_string (stream, name);
  1672.       fprintf (stream, "\n");
  1673.     }
  1674. }
  1675.  
  1676. /* Emit a linenumber to a stream.  */
  1677.  
  1678. void
  1679. alpha_output_lineno (stream, line)
  1680.      FILE *stream;
  1681.      int line;
  1682. {
  1683.   if (! TARGET_GAS && write_symbols == DBX_DEBUG)
  1684.     {
  1685.       /* mips-tfile doesn't understand .stabd directives.  */
  1686.       ++sym_lineno;
  1687.       fprintf (stream, "$LM%d:\n\t%s %d,0,%d,$LM%d\n",
  1688.            sym_lineno, ASM_STABN_OP, N_SLINE, line, sym_lineno);
  1689.     }
  1690.   else
  1691.     fprintf (stream, "\n\t.loc\t%d %d\n", num_source_filenames, line);
  1692. }
  1693.